package com.zymail.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zymail.bean.ZyClass;
import com.zymail.bean.ZyGood;
import com.zymail.mapper.ZyGoodMapper;
import com.zymail.service.ZyClassService;
import com.zymail.service.ZyGoodService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Wrapper;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Dorado
 * @since 2021-04-12
 */
@Service
public class ZyGoodServiceImpl extends ServiceImpl<ZyGoodMapper, ZyGood> implements ZyGoodService {

    @Autowired
    public ZyClassService classService;

    @Autowired
    public ZyGoodService goodService;


    @Override
    public List<ZyGood> getSortedGood() {
        List<ZyClass> classList = classService.getSortedClass();
        List<ZyGood> res = new ArrayList<>();

        for (ZyClass zyClass : classList) {
            QueryWrapper<ZyGood> wrapper = new QueryWrapper<>();
            wrapper.eq("class_id", zyClass.getId());
            res.addAll(goodService.list(wrapper));
        }

        return res;
    }
}
